package evolutionaryballoons.visual;

import evolutionaryballoons.Balloon;
import evolutionaryballoons.Currents;
import evolutionaryballoons.Points;
import evolutionaryballoons.behavior.Behavior;
import evolutionaryballoons.behavior.genetic.BalloonSimulation;
import evolutionaryballoons.behavior.genetic.GeneticBehavior;
import evolutionaryballoons.behavior.genetic.Node;

public class BalloonSimulator implements Runnable {
	private BalloonSimulation simulation;
	private WorldView worldview;
	
	public BalloonSimulator(Balloon balloon, WorldView worldview, Points points, Currents currents, Node rootNode) {
		Behavior behavior = new GeneticBehavior(balloon, points, currents, rootNode);
		this.simulation = new BalloonSimulation(balloon, points, behavior);
		this.worldview = worldview;
	}
	
	@Override
	public void run() {
		while(simulation.isActive()) {
			simulation.step();
			worldview.draw();
			
			if (simulation.tick %5 == 0) {
				worldview.mark();
			}
			
			try {
				Thread.sleep(VisualTest.sFrameRate);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		System.out.println("Collected " + simulation.getCollected() + " in " + simulation.tick + " ticks");
	}
}
